/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Properties;
using System.Windows.Forms;
using ELE.EnterpriseLibrary.Data.Configuration.Design.Properties;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;

namespace ELE.EnterpriseLibrary.Data.Configuration.Design
{
	class ObjectMappingCommandRegistrar : CommandRegistrar
	{
		public ObjectMappingCommandRegistrar(IServiceProvider serviceProvider) : base(serviceProvider)
		{
		}

		public override void Register()
		{
			AddObjectMappingSettingsCommand();
			AddDefaultCommands(typeof(ObjectMappingSettingsNode));

			AddSqlQueryCommand();
			AddDefaultCommands(typeof(SqlQueryNode));

      AddMappingQueryCommand();
      AddDefaultCommands(typeof(ObjectSqlMappingNode));

      AddQueryBuilderCommand();
      AddDefaultCommands(typeof(QueryBuilderNode));

      AddAssembliesCommand();
      AddDefaultCommands(typeof(ObjectTypeAssemblyNode));

      AddTypesCommand();
      AddDefaultCommands(typeof(ObjectTypeDefNode));

      AddObjectMappingCommand();
      AddDefaultCommands(typeof(ObjectMappingNode));

      AddObjectMappingTableCommand();
      AddDefaultCommands(typeof(ObjectMappingTableNode));

      AddObjectBindingCommand();
      AddDefaultCommands(typeof(ObjectBindingNode));

      AddSqlQueryMappingReferenceCommand();
      AddDefaultCommands(typeof(ObjectMappingReferenceNode));

      AddSqlQueryMappingBindingOverwriteCommand();
      AddDefaultCommands(typeof(ObjectBindingOverwriteNode));
		}
		
		private void AddMappingQueryCommand()
    {
      AddCommandToNodeMultiple(typeof(ObjectSqlMappingNode),
        typeof(ObjectSqlMappingCollectionNode),
        Resource.SqlMappingMenuText);
		}

		private void AddSqlQueryCommand()
    {
      AddCommandToNodeMultiple(typeof(SqlQueryNode),
        typeof(SqlQueryCollectionNode),
        Resource.SqlQueryMenuText);
    }

    private void AddQueryBuilderCommand()
    {
      AddCommandToNodeMultiple(typeof(QueryBuilderNode),
        typeof(QueryBuilderCollectionNode),
        Resource.QueryBuilderMenuText);
    }

    private void AddAssembliesCommand()
    {
      AddCommandToNodeMultiple(typeof(ObjectTypeAssemblyNode),
        typeof(ObjectTypeAssemblyCollectionNode),
        Resource.AssembliesMenuText);
    }

    private void AddTypesCommand()
    {
      AddCommandToNodeMultiple(typeof(ObjectTypeDefNode),
        typeof(ObjectTypeDefCollectionNode),
        Resource.TypesMenuText);
    }

    private void AddObjectMappingCommand()
    {
      AddCommandToNodeMultiple(typeof(ObjectMappingNode),
        typeof(ObjectSqlMappingNode),
        Resource.ObjectMappingMenuText);
    }
    private void AddObjectMappingTableCommand()
    {
      AddCommandToNodeMultiple(typeof(ObjectMappingTableNode),
        typeof(ObjectMappingNode),
        Resource.ObjectMappingTableMenuText);
    }
    private void AddObjectBindingCommand()
    {
      AddCommandToNodeMultiple(typeof(ObjectBindingNode),
        typeof(ObjectMappingTableNode),
        Resource.ObjectBindingMenuText);
    }
    private void AddSqlQueryMappingReferenceCommand()
    {
      AddCommandToNodeMultiple(typeof(ObjectMappingReferenceNode),
        typeof(SqlQueryNode),
        Resource.SqlQueryMappingReferenceMenuText);
    }
    private void AddSqlQueryMappingBindingOverwriteCommand()
    {
      AddCommandToNodeMultiple(typeof(ObjectBindingOverwriteNode),
        typeof(ObjectMappingReferenceNode),
        Resource.SqlQueryBindingOverwriteMenuText);
    }
    private void AddCommandToNodeMultiple(Type nodeType, Type parentNodeType, string nodeName)
    {
      AddMultipleChildNodeCommand(nodeName,
        string.Format(Resource.Culture, Resource.GenericCreateStatusText, nodeName),
        nodeType,
        parentNodeType);
    }
    private void AddObjectMappingSettingsCommand()
		{
			ConfigurationUICommand cmd = ConfigurationUICommand.CreateSingleUICommand(ServiceProvider, 
				Resource.ObjectMappingSettingsUICommandText,
				Resource.ObjectMappingSettingsUICommandLongText,
				new AddObjectMappingSettingsNodeCommand(ServiceProvider),
        typeof(ObjectMappingSettingsNode));
			AddUICommand(cmd, typeof(ConfigurationApplicationNode));
		}
	}
}
